﻿namespace FlotDotNet
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;

    /// <summary>
    /// Represents an axis on the chart
    /// </summary>
    public class FlotAxis : FlotElementBase
    {
        private FlotTickOptions mTicks;

        /// <summary>
        /// Creates a new instance of the FlotAxis class
        /// </summary>
        /// <param name="elementName">Defines the name of the axis</param>
        internal FlotAxis(string elementName)
        {
            ElementName = elementName;
        }

        //internal string ElementName { get { return ElementName
        
        /// <summary>
        /// Gets or sets a value which indicates that the axis is to be shown.
        /// If you don't set this option (i.e. it is null), visibility is auto-detected, i.e. the axis will show up if there's data associated with it.
        /// </summary>
        [FlotProperty]
        public bool? Show { get; set; }
        
        /// <summary>
        /// Gets or sets the position where the axis is to be placed
        /// </summary>
        [FlotProperty(SerializationOptions = FlotSerializationOptions.LowerCase | FlotSerializationOptions.QuoteValue)]
        public FlotAxisPosition? Position { get; set; }
       
        /// <summary>
        /// Gets or sets the axis mode.
        /// The default of null means as decimal numbers.
        /// </summary>
        [FlotProperty(SerializationOptions = FlotSerializationOptions.LowerCase | FlotSerializationOptions.QuoteValue)]
        public FlotAxisMode? Mode { get; set; }
        
        /// <summary>
        /// Gets or sets the color of the labels and ticks for the axis (default is the grid color)
        /// </summary>
        [FlotProperty]
        public FlotColor Color { get; set; }
        
        /// <summary>
        /// Gets or sets the precise minimum value on the scale.
        /// If you don't specify either of them, a value will automatically be chosen based on the minimum/maximum data values. 
        /// </summary>
        [FlotProperty]
        public double? Min { get; set; }
        
        /// <summary>
        /// Gets or sets the precise maximum value on the scale.
        /// If you don't specify either of them, a value will automatically be chosen based on the minimum/maximum data values. 
        /// </summary>
        [FlotProperty]
        public double? Max { get; set; }
        
        /// <summary>
        /// Gets or sets the fraction of margin that the scaling algorithm will add to avoid that the outermost points ends up on the grid border.
        /// Note that this margin is only applied when a min or max value is not explicitly set.
        /// If a margin is specified, the plot will furthermore extend the axis end-point to the nearest whole tick.
        /// The default value is null for the x axes and 0.02 for y axes which seems appropriate for most cases.
        /// </summary>
        [FlotProperty]
        public double? AutoscaleMargin { get; set; }
        
        /// <summary>
        /// Gets or sets a callback you can put in to change the way the data is drawn.
        /// Value can be null or fn: number -> number
        /// </summary>
        [FlotProperty]
        public string Transform { get; set; }
        
        /// <summary>
        /// Gets or sets a callback you can put in to change the way the data is drawn.
        /// Value can be null or fn: number -> number
        /// </summary>
        [FlotProperty]
        public string InverseTransform { get; set; }
        
        /// <summary>
        /// Get or sets the chart ticks.
        /// If you don't specify any ticks, a tick generator algorithm will make some for you.
        /// If you don't want any ticks at all, set to 0 or an empty array
        /// </summary>
        [FlotProperty]
        public FlotTickOptions Ticks
        {
            get
            {
                if (mTicks == null)
                    mTicks = new FlotTickOptions();
                return mTicks;
            }
            set { mTicks = value; }
        }
        
        /// <summary>
        /// Gets or sets the tick interval size.
        /// If you set it to 2, you'll get ticks at 2, 4, 6, etc
        /// </summary>
        [FlotProperty]
        public int? TickSize { get; set; }
        
        /// <summary>
        /// Gets or sets the minimum tick value to be displayed
        /// </summary>
        [FlotProperty]
        public int? MinTickSize { get; set; }
        
        /// <summary>
        /// Sets the color of ticks separately for more fine-grained control (otherwise it's autogenerated as the base color with some transparency).
        /// </summary>
        [FlotProperty]
        public FlotColor TickColor { get; set; }
        
        /// <summary>
        /// Specifies the number of decimals to display in the ticks
        /// </summary>
        [FlotProperty]
        public int? TickDecimals { get; set; }
        
        /// <summary>
        /// Provides ultimate control over how ticks are formatted.
        /// The function is passed two parameters, the tick value and an axis object with information, and should return a string
        /// </summary>
        [FlotProperty]
        public string TickFormatter { get; set; }
        
        /// <summary>
        /// Specifies a fixed size width of the tick labels in pixels
        /// </summary>
        [FlotProperty]
        public int? LabelWidth { get; set; }
        
        /// <summary>
        /// Specifies a fixed size height of the tick labels in pixels
        /// </summary>
        [FlotProperty]
        public int? LabelHeight { get; set; }
        
        /// <summary>
        /// The length of the tick lines in pixels.
        /// By default, the innermost axes will have ticks that extend all across the plot, while any extra axes use small ticks.
        /// A value of null means use the default, while a number means small ticks of that length - set it to 0 to hide the lines completely.
        /// </summary>
        [FlotProperty]
        public int? TickLength { get; set; }
        
        /// <summary>
        /// Set to the number of another axis, e.g. alignTicksWithAxis: 1, Flot will ensure that the autogenerated ticks of this axis are aligned with the ticks of the other axis
        /// </summary>
        [FlotProperty]
        public int? AlignTicksWithAxis { get; set; }
        
        /// <summary>
        /// If an axis isn't shown, Flot should reserve space for it
        /// </summary>
        [FlotProperty]
        public bool? ReserveSpace { get; set; }
        
        /// <summary>
        /// Get or sets the format string to use when formatting time
        /// </summary>
        [FlotProperty(Name = "timeformat", SerializationOptions = FlotSerializationOptions.QuoteValue)]
        public string TimeFormat { get; set; }

        /// <summary>
        /// Axis label.
        /// </summary>
        [FlotProperty(SerializationOptions = FlotSerializationOptions.QuoteValue)]
        public string AxisLabel { get; set; }
    }
}